class MutLoadout extends Mutator
    config;

var localized string LoadoutDisplayText, LoadoutDescText, LoadoutDisplayTextName;
var bool bInitialized;
var int LoadoutNum;
var() config string LoadoutName,
                    Loadout1,
                    Loadout2,
                    Loadout3,
                    Loadout4,
                    Loadout5,
                    Loadout6,
                    Loadout7,
                    Loadout8,
                    Loadout9;

function Initialize()
{
	bInitialized = true;
}

function bool CheckReplacement( Actor Other, out byte bSuperRelevant )
{
	if ( !bInitialized )
		Initialize();

	bSuperRelevant = 0;

    //Give player the weapons it's supposed to start with
	if (Other.isA('xPawn'))
	{

		if( Other.isA('Monster') ) return True;

	    // Give the extra Guns.
		xPawn(Other).RequiredEquipment[2] = Loadout1;
		xPawn(Other).RequiredEquipment[3] = Loadout2;
		xPawn(Other).RequiredEquipment[4] = Loadout3;
		xPawn(Other).RequiredEquipment[5] = Loadout4;
		xPawn(Other).RequiredEquipment[6] = Loadout5;
		xPawn(Other).RequiredEquipment[7] = Loadout6;
		xPawn(Other).RequiredEquipment[8] = Loadout7;
		xPawn(Other).RequiredEquipment[9] = Loadout8;
		xPawn(Other).RequiredEquipment[9] = Loadout9;
	}
	return true;
}

function bool ReplaceWith(actor Other, string aClassName)
{
	local Actor A;
	local class<Actor> aClass;
	local bool bMustard;

	if ( aClassName == "" )
		return true;

	aClass = class<Actor>(DynamicLoadObject(aClassName, class'Class'));
	if ( aClass != None )
	{
		bMustard = aClass.default.bGameRelevant;
		aClass.default.bGameRelevant = True;
		aClass.static.StaticSaveConfig();
		A = Spawn(aClass,Other.Owner,Other.tag,Other.Location, Other.Rotation);
		A.bGameRelevant = bMustard;
		aClass.default.bGameRelevant = bMustard;
		aClass.static.StaticSaveConfig();

	}
	if ( A != None )
	{
		A.event = Other.event;
		A.tag = Other.tag;
		return true;
	}
	return false;
}

function ModifyPlayer(Pawn Other)
{
    local tfpri pri;
    if(other!=none && other.PlayerReplicationInfo!=none && tfpri(other.PlayerReplicationInfo)!= none)
    {
        pri=tfpri(other.PlayerReplicationInfo);
    }
	super.ModifyPlayer(Other);
}


static function FillPlayInfo(PlayInfo PlayInfo)
{
	local array<CacheManager.WeaponRecord> Recs;
	local string WeaponOptions;
	local int i;

	Super.FillPlayInfo(PlayInfo);

	WeaponOptions $= ";**NONE**";
	class'CacheManager'.static.GetWeaponList(Recs);
	for (i = 0; i < Recs.Length; i++)
	{
		if (WeaponOptions != "")
			WeaponOptions $= ";";

		WeaponOptions $= Recs[i].ClassName $ ";" $ Recs[i].FriendlyName;
	}

    PlayInfo.AddSetting(default.RulesGroup, "LoadoutName", default.LoadoutDisplayTextName, 0, 1, "Text");
	PlayInfo.AddSetting(default.RulesGroup, "Loadout1", default.LoadoutDisplayText, 0, 2, "Select", WeaponOptions);
	PlayInfo.AddSetting(default.RulesGroup, "Loadout2", default.LoadoutDisplayText, 0, 2, "Select", WeaponOptions);
	PlayInfo.AddSetting(default.RulesGroup, "Loadout3", default.LoadoutDisplayText, 0, 2, "Select", WeaponOptions);
	PlayInfo.AddSetting(default.RulesGroup, "Loadout4", default.LoadoutDisplayText, 0, 2, "Select", WeaponOptions);
	PlayInfo.AddSetting(default.RulesGroup, "Loadout5", default.LoadoutDisplayText, 0, 2, "Select", WeaponOptions);
	PlayInfo.AddSetting(default.RulesGroup, "Loadout6", default.LoadoutDisplayText, 0, 2, "Select", WeaponOptions);
	PlayInfo.AddSetting(default.RulesGroup, "Loadout7", default.LoadoutDisplayText, 0, 2, "Select", WeaponOptions);
	PlayInfo.AddSetting(default.RulesGroup, "Loadout8", default.LoadoutDisplayText, 0, 2, "Select", WeaponOptions);
	PlayInfo.AddSetting(default.RulesGroup, "Loadout9", default.LoadoutDisplayText, 0, 2, "Select", WeaponOptions);
}

static event string GetDescriptionText(string PropName)
{
	if (PropName == "Loadout")
		return default.LoadoutDescText;

	return Super.GetDescriptionText(PropName);
}

defaultproperties
{
     LoadoutDisplayTextName="Loadout Name"
     LoadoutDisplayText="Loadout Item"
     LoadoutDescText="Allows you to set your loadouts"
     GroupName="Loadout 1"
     FriendlyName="Loadout 1"
     Description="Allows you to set your loadouts"
     bNetTemporary=True
     bAlwaysRelevant=True
     RemoteRole=ROLE_SimulatedProxy
     LoadoutNum=1
}
